import java.util.HashMap;
import java.util.Map;

class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> hash = new HashMap<>();
        int[] ret = new int[2];
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (hash.containsKey(target - nums[i])) {
                ret[0] = i;
                ret[1] = hash.get(target - nums[i]);
                break;
            }
            hash.put(nums[i], i);
        }
        return ret;
    }
}